<#import '/ftlLibrary/properteisVariable.ftl' as pv/>
<style>
    input,select{
        height: 30px!important;
    }
    .control-label{
        margin-bottom:0px!important;
        line-height: 30px!important;
    }
    .checkboxStyle label{
        margin:0px;
    }
    .bootbox-expand-button {
        width: 19px;
        height: 19px;
        border: none;
        cursor: pointer;
        -webkit-appearance: none;
        float: right;
        top: -18px;
        left: -30px;
        position: relative;
        background: #E9F5FF url("assets/img/nav-img/icon_window.png") no-repeat 0 0;
    }

    .bootbox-close-button {
        width: 19px;
        height: 19px;
        border: none;
        cursor: pointer;
        -webkit-appearance: none;
        float: right;
        top: 4px;
        left: -5px;
        position: relative;
        background: #E9F5FF url("assets/img/nav-img/icon_close.png") no-repeat 0 0;
    }

    .margin-bottom-15 {
        margin-bottom: 15px !important;
    }

    .expandView {
        width: 100%;
    }
    .addPaymentDialog  .modal-dialog{
        width: 50%;
    }
</style>
<div class="row" >
    <div class="row" style="text-align: center;padding-top: 1px;min-height: 56px">
        <div class="col-xs-6 col-xs-offset-3">
            <div class="col-xs-4 nopadding">
                <button type="btn" class="btn col-xs-12 " onclick="addPayment(this)" flag="1" style="border-color: #5db2ff!important;float:left">订金</button>
            </div>
            <div class="col-xs-4 nopadding">
                <button type="btn" class="btn col-xs-12 " onclick="addPayment(this)" flag="2" style="border-color: #5db2ff!important;float:left">课时包</button>
            </div>
            <div class="col-xs-4 nopadding">
                <button type="btn" class="btn col-xs-12 " onclick="addPayment(this)" flag="3" style="border-color: #5db2ff!important;background-color: #5db2ff;float:left">其它</button>
            </div>
        </div>
    </div>
    <form class="editForm" action="${saveUrl}" method="post" responseType="JSON" role="form"
          id="editForm_${serializeNum}"          data-bv-submitButtons="#editFormSubmitBtn_${serializeNum}"
          data-bv-message="This value is not valid"
          data-bv-feedbackicons-valid="glyphicon glyphicon-ok"
          data-bv-feedbackicons-invalid="glyphicon glyphicon-remove"
          data-bv-feedbackicons-validating="glyphicon glyphicon-refresh">
        <input type="hidden" name="id" value="${editEntity.id}">
        <input type="hidden" name="targetdataid" value="${targetdataid}">
        <input type="hidden" class="empAdminUserId"  value="${empAdminUserId}">
        <input type="hidden" name="memberType" value="${memberType}">
        <!--<input type="hidden" class="paymentType" name="paymentType" value="2"/>-->
        <input type="hidden" class="flag" name="flag" value="3"/>
        <input type="hidden" class="menu" name="menu" value="${menu}">
        <input type="hidden" class="user" name="user" value="${user}">
        <div class="user hidden">
            <div class="col-xm-12 col-sm-6 col-lg-12 margin-bottom-15">
                <div class="form-group">
                    <label for="name" class="col-sm-2 col-sm-offset-2 control-label no-padding-right">客户姓名：</label>
                    <div class="col-sm-4">
                        <input data-bv-message="The field is not valid" size="50" name="name" alt="客户姓名" id="name"
                               placeholder="客户姓名" type="text" title="客户姓名" class="form-control searchName"
                               value="${editEntity.number}"  onblur="searchName()"/>
                        <span class="text"></span>
                        <select name="stuId" id="stuId" class="col-sm-5 stuId " value=""
                                style="height: 32px;" onchange="studentCheck(this)">

                        </select>
                    </div>
                </div>
            </div>

            <div class="col-xm-12 col-sm-6 col-lg-12 margin-bottom-15">
                <div class="form-group">
                    <label for="contactPhone" class="col-sm-2 col-sm-offset-2 control-label no-padding-right">联系电话：</label>
                    <div class="col-sm-4">
                        <input data-bv-message="The field is not valid" size="50" name="contactPhone" alt="联系电话" id="contactPhone"
                               placeholder="联系电话" type="text" title="联系电话" class="form-control"
                               value="${editEntity.contactPhone}"/>
                        <span class="text"></span>
                    </div>
                </div>
            </div>
        </div>
        <div class="deposit show">
            <div class="col-xm-12 col-sm-6 col-lg-12 margin-bottom-15">
                <div class="form-group">
                    <label for="amount" class="col-sm-2 col-sm-offset-2 control-label no-padding-right">费用金额：</label>
                    <div class="col-sm-4">
                        <input data-bv-integer-message="The field is number" data-bv-message="The field is not valid"
                               data-bv-integer="true" size="11" name="amount" id="amount" alt="费用金额" id="amount" placeholder="费用金额"
                               type="text" title="费用金额" class="form-control" value="${editEntity.amount}"/>
                        <span class="text"></span>
                    </div>
                </div>
            </div>

            <div class="col-xm-12 col-sm-6 col-lg-12 margin-bottom-15 ">
                <div class="form-group">
                    <label for="paymentType"
                           class="col-sm-3 col-sm-offset-1 control-label no-padding-right"><span style="color: red">*</span>费用类型：</label>
                    <div class="col-sm-7 control-label text-align-left checkboxStyle" >
                        <label >
                            <input type="radio" name="paymentType" value="5" id="paymentType" style="margin-right: 5px;opacity: 1;position: static;height: 18px!important;" checked >
                        </label >
                        <label style="margin-right: 10px">一次性物品费</label>
                        <label >
                            <input type="radio" name="paymentType" value="4" style="margin-right: 5px;opacity: 1;position: static;height: 18px!important;" >
                        </label>
                        <label >餐点费 <span class="text">日标准：${dayMealFee}元/日</span></label>
                        <label>
                            <input type="radio" name="paymentType" value="6" style="margin-right: 5px;opacity: 1;position: static;height: 18px!important;" >
                        </label>
                        <label >其他费用</label>

                    </div>
                </div>
            </div>
            <div class="col-xm-12 col-sm-6 col-lg-12 margin-bottom-15 ">
                <div class="form-group">
                    <label for="adminUserId"
                           class="col-sm-3 col-sm-offset-1 control-label no-padding-right">所属顾问：</label>
                    <div class="col-sm-4">
                        <select name="empAdminUserId" id="adminUserId"
                                class="col-sm-12 adminUserId toOtherPaymentadminUserId" value=""
                                style="height: 32px;">
                        </select>
                    </div>
                </div>
            </div>

            <div class="col-xm-12 col-sm-6 col-lg-12 margin-bottom-15">
                <div class="form-group">
                    <label for="remark" class="col-sm-2 col-sm-offset-2 control-label no-padding-right">费用说明：</label>
                    <div class="col-sm-6">
                        <textarea class="form-control" name="remark" size="500" rows="2" style="resize:none" id="remark" value="${editEntity.remark}"></textarea>
                        <!--<input data-bv-message="The field is not valid" size="500" name="remark" alt="备注" id="remark"-->
                        <!--placeholder="备注" type="text" title="备注" class="form-control"-->
                        <!--value="${editEntity.remark}"/>-->
                        <!--<span class="text"></span>-->
                    </div>
                </div>
            </div>
            <div class="col-sm-12 ">
                <div class="text-align-center">
                    <button style="width: 80px;margin-right: 20px" type="submit" class="btn btn-blue" id="depositEditFormSubmitBtn_${serializeNum}">确定</button>
                    <input style="width: 80px" type="button" class="btn btn-blue" data-dismiss="modal" value="取消"/>
                </div>
            </div>
        </div>
    </form>
</div>
<script src="assets/js/validation/bootstrapValidator_init.js"></script>
<script>
    $(function () {
        var type = $(".packageType").val();
        //console.log(type);

        /*var menu = $(".menu").val();
        //console.log(menu);*/
        var user = $(".user").val();
        //console.log(user);
        /*if(menu == 1){
            $(".menu").removeClass("hidden").addClass("show");
        }*/
        if(user == 1){
            $(".user").removeClass("hidden").addClass("show");
        }
        ajaxStaffList();

    });
    function addPayment(that) {
        var user = $(".user").val();
        var targetdataid = $('input[name="targetdataid"]').val();
        var flag = $(that).attr("flag");
        var htmlTitle= "";
        if(flag == "1"){
            htmlTitle= "订金";
        }
        if(flag == "2"){
            htmlTitle= "课时包";
        }
        if(flag == "3"){
            htmlTitle= "其它";
        }
        bootbox.hideAll();
        console.log(flag);
        ajaxRequest("tssPaymentController/toAddedPaymentView.do", {
            targetdataid:targetdataid,
            flag:flag,
            user:user
        }, function (html) {
            getTopWin().bootbox.dialog({
                message: html,
                title: htmlTitle,
                className: 'myDialog '
            });
            $(".modal-header").find(".bootbox-close-button").removeClass("close");
            $(".modal-header").find(".bootbox-close-button").html("");
        }, function () {
            ajaxError("加载页面失败!")
        }, "get", "html")
    }
    function searchName() {
        var name = $('.searchName').val();
        console.log(name);
        //console.log(serializeNum);
        ajaxRequest("tssStudentController/findStudentByName.do", {
            name: name
        }, function (result) {
            var data1=result.data;
            //alert(result);
            //alert(result.data);
            var arr=['<option value="0">请选择</option>'];
            for (var i = 0; i< data1.length; i++) {
                arr.push('<option value="' + data1[i].id + '"  name="'+data1[i].name+ '" adminUserId="'+data1[i].adminUserId+ '" contactPhone="'+data1[i].contactPhone+'">' + data1[i].name + '</option>')
            }
            //alert(arr);
            $(".stuId").html(arr.join(''));
        }, function () {
            html = '<p class="no-goods">无匹配数据，点击快速新建</p>';
            $('.searcher-list').html(html);
        }, "get", "json")
    };


    function studentCheck(that) {
        var id = $(that).attr("id");

        var contactPhone = $("#stuId").find("option:selected").attr("contactPhone");
        var name = $("#stuId").find("option:selected").attr("name");
        var adminUserId = $("#stuId").find("option:selected").attr("adminUserId");

        console.log(contactPhone);
        console.log(contactPhone);
        console.log(name);
        console.log(adminUserId);


        $('input[name="stuId"]').val(id);
        $('input[name="name"]').val(name);
        $('input[name="contactPhone"]').val(contactPhone);
        $(".adminUserId").val(adminUserId);


    }


    function ajaxStaffList() {
        ajaxRequest("sysAdminUserController/getPostListByDuty.do", {
            duty: 4
        }, function (result) {
            var data = result.data;
            var arr = ['<option value="0">请选择</option>'];
            for (var i = 0; i < data.length; i++) {
                arr.push('<option value="' + data[i].id + '">' + data[i].realName + '</option>')
            }
            console.log(i);
            $('.toOtherPaymentadminUserId').html(arr.join(''));
        }, function () {
            ajaxError("加载员工信息失败");
        }, "post", "json")
    };


    $(".selectpicker_${serializeNum}").select2();

    $("#editForm_${serializeNum}").bind("ajaxSubmitCallback", function (event, result) {
        alert(result.resMsg);
        if (result.resCode == 200) {
            bootbox.hideAll();
        }
    });



    /**
     * 选择课时包
     * @param that
     */
    function packageCheck(that) {
        var id = $(that).attr("id");
        if (id == 'dearSonPackageId') {
            var packageId = $("#dearSonPackageId").find("option:selected").attr("packageId");
            var packageOriginalUnitPrice = $("#dearSonPackageId").find("option:selected").attr("packageOriginalUnitPrice");
            var packageValidDate = $("#dearSonPackageId").find("option:selected").attr("packageValidDate");
            var packageTotalClassHour = $("#dearSonPackageId").find("option:selected").attr("packageTotalClassHour");

            console.log(packageId);
            console.log(packageOriginalUnitPrice);
            console.log(packageValidDate);
            console.log(packageTotalClassHour);

            $('input[name="classHour"]').eq(0).val(packageTotalClassHour);
            $('input[name="originalUnitPrice"]').eq(0).val(packageOriginalUnitPrice);
            $('input[name="dearSonValidDate"]').eq(0).val(packageValidDate);
        } else {
            var packageId = $("#packageId").find("option:selected").attr("packageId");
            var packageAttendanceDay = $("#packageId").find("option:selected").attr("packageAttendanceDay");
            var packageSumPrice = $("#packageId").find("option:selected").attr("packageSumPrice");
            var packageValidDate = $("#packageId").find("option:selected").attr("packageValidDate");


            $('input[name="attendanceDay"]').eq(0).val(packageAttendanceDay);
            $('input[name="sumPrice"]').eq(0).val(packageSumPrice);
            $('input[name="validDate"]').eq(0).val(packageValidDate);


        }
    }

</script>